public class text12 {
    public volatile static int flag=0;

    public static void main(String[] args) {
        Thread thread1=new Thread(new Runnable() {
            @Override
            public void run() {
                while(flag==0)
                {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    ;

                }

            }
        });
        Thread thread2=new Thread(new Runnable() {
            @Override
            public void run() {
                flag=1;

            }
        });
        thread1.start();
        thread2.start();

        //System.out.println("两个线程都运行结束了");


    }
}
